package com.swxc.ssm.controller;

import com.sun.xml.internal.bind.v2.model.core.ID;
import com.swxc.ssm.po.Course;
import com.swxc.ssm.po.User;
import com.swxc.ssm.service.CourseService;
import com.swxc.ssm.service.UserService;
import com.swxc.ssm.service.UsertocouService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Description
 * Author shadowolf
 * Date 2017/7/27. 12:02
 * Version 1.0
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private UsertocouService usertocouService;
    @Autowired
    private CourseService courseService;

    @RequestMapping("toPersonal")
    public ModelAndView toPersonal(HttpSession session){

        ModelAndView modelAndView = new ModelAndView();
        User user =(User)  session.getAttribute("user");

        session.removeAttribute("user_course");
        List user_course = usertocouService.selectByUserID(user.getID());
        session.setAttribute("user_course",user_course);

        modelAndView.setViewName("personal");
        return modelAndView;
    }
    @RequestMapping("/selectByStatus")
    public ModelAndView selectByStatus(@RequestParam(value="id", required = false) String id  , HttpSession session){
        ModelAndView modelAndView = new ModelAndView();
        User user =(User)  session.getAttribute("user");
        List user_course =  usertocouService.selectByUserStatus(user.getID(),Integer.parseInt(id));
        session.removeAttribute("user_course");
        session.setAttribute("user_course",user_course);

        modelAndView.setViewName("personal");
        return modelAndView;
    }

    @RequestMapping("/selectByPrimaryKey")
    public ModelAndView selectByPrimaryKey(Integer ID) throws Exception {

        ModelAndView modelAndView = new ModelAndView();

        modelAndView.setViewName(" ");
        return modelAndView;

    }



    @RequestMapping("/deleteByPrimaryKey")
    public ModelAndView deleteByPrimaryKey(Integer ID) {
        userService.deleteByPrimaryKey(5);
        ModelAndView modelAndView = new ModelAndView();
        return modelAndView;
    }

    @RequestMapping("/insert")
    public ModelAndView insert(User record) {
        userService.insert(record);
        ModelAndView modelAndView = new ModelAndView();
        return modelAndView;
    }

    @RequestMapping("/insertSelective")
    public ModelAndView insertSelective(User record) {
        userService.insertSelective(record);
        ModelAndView modelAndView = new ModelAndView();
        return modelAndView;
    }

    @RequestMapping("/updateByPrimaryKeySelective")
    public ModelAndView updateByPrimaryKeySelective(User record) {
        userService.updateByPrimaryKeySelective(record);
        ModelAndView modelAndView = new ModelAndView();
        return modelAndView;
    }

    @RequestMapping("/updateByPrimaryKey")
    public ModelAndView updateByPrimaryKey(User record) {
        userService.updateByPrimaryKey(record);
        ModelAndView modelAndView = new ModelAndView();
        return modelAndView;
    }

    @RequestMapping("/selectByEmail")
    public ModelAndView selectByEmail(String email){
        userService.selectByEmail(email);
        ModelAndView modelAndView = new ModelAndView();
        return modelAndView;
    }

}
